home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
comm
/
tcp
/
rxsocket.lha
/
rxsocket
/
Examples
/
daytimeudp.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-05-29
|
1KB
|
59 lines
/*
daytime udp client - Usage: daytimeudp host
daytime/udp client, to use with dtudpserv or
as general client for daytime/udp.
*/
if ~open("STDERR","*","W") then STDERR="STDOUT"
l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
prg=ProgramName("NOEXT")
if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then
call err "can't find" result,1
if ~RMH_ReadArgs("HOST/A") then do
call PrintFault()
exit
end
remote.AddrAddr=resolve(parm.0.value)
if remote.AddrAddr==-1 then call err "Host <"parm.0.value"> not found.",1
if GetServByName("SE","daytime","udp") then
remote.AddrPort=se.ServPort
else remote.AddrPort=13
sock=socket("INET","DGRAM")
if sock<0 then call err "no socket"
call IOCtlSocket(sock,"FIONBIO",1)
sig=2**AllocSignal()
set.SigEventMask=sig
call SetSocketBase("SET")
call SetSockOpt(sock,"SOCKET","EVENTMASK","ERROR READ")
if connect(sock,"REMOTE")<0 then call err "connect error"
if send(sock,"A"x)~=1 then call err "send error"
wait.read.0=sock
wait.ex.0=sock
res=WaitSelect("WAIT",10,,sig)
if res<0 then call err "wait error"
if res==0 & and(wait.signals,sig)==0 then call err "timeout",1
call GetSocketEvents("EVENTS")
if events.error then call err "can't connect to" host
n=recv(sock,"BUF")
if len<0 then call "recv error"
call WriteCH("STDOUT",buf)
exit
err:
parse arg msg,noerr
if noerr~=1 then msg = msg "("ErrorString()")"
call Writeln(STDERR,prg": "msg)
exit